package com.archtecture.model.patterns;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.spgf.model.dao.util.CustomSQLiteOpenHelper;

public class DAOSqliteHelper {

	private final Context					context;

	private Cursor							cursor;

	private final CustomSQLiteOpenHelper	custonDatabase;

	private SQLiteDatabase					database;

	public DAOSqliteHelper(final Context context) {
		this.context = context;
		custonDatabase = new CustomSQLiteOpenHelper(context);
		// DatabaseUtil.getInstance().importarBancoDados(context, custonDatabase);
	}

	protected void close() {

		if (cursor != null && !cursor.isClosed()) {
			cursor.close();
		}

		if (database != null && database.isOpen()) {
			database.close();
		}

		if (custonDatabase != null) {
			custonDatabase.close();
		}
	}

	protected Context getContext() {
		return context;
	}

	public Cursor getCursor() {
		return cursor;
	}

	protected SQLiteDatabase getDatabase() {
		return database;
	}

	protected void openReadable() {
		database = custonDatabase.getReadableDatabase();
	}

	protected void openWritable() {
		database = custonDatabase.getWritableDatabase();
	}

	public void setCursor(Cursor cursor) {
		this.cursor = cursor;
	}

}
